<?PHP
include("service.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1"> 
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<?PHP
if(isset($_GET["lesson_id"])){
	$lesson_id = $_GET["lesson_id"];
}else if(isset($_POST["lesson_id"])){
	$lesson_id = $_POST["lesson_id"];
}
if(isset($_GET["m_id"])){
	$m_id = $_GET["m_id"];
}else if(isset($_POST["m_id"])){
	$m_id = $_POST["m_id"];
}
//echo $lesson_id.":".$m_id;
$question = php_getquestion();
//echo "<pre>";print_r($question);
if($question["result"]<>"OK"){
	echo $question["result"];
	exit;	
}

?>
<table width="100%" border="0">
<?PHP
$i = 0;
foreach($question["question"] as $key => $question_detail) {
	$i++;
	if($i%2==0){
		$bg = "#FFFFFF";
	}else{
		$bg = "#DBE9F3";
	}
?>
  <tr bgcolor="<?=$bg?>">
    <td width="293">คำถาม : <?=$question_detail[question_detail]?></td>
  </tr>
  <?PHP
	if($question_detail[pic_url]==''){
		
	}else{
	?>
  <tr bgcolor="<?=$bg?>">
    <td width="293">
    
    
    <img src="<?=$question_detail[pic_url]?>" width="100%" height="50%" />
    
    </td>
  </tr>
 <? } ?>
<?PHP
	foreach($question_detail[choise] as $key => $q_choise) {
?>
  <tr bgcolor="<?=$bg?>">
    <td>
      <input type="radio" name="radio<?=$i?>" id="radio" value="<?=$q_choise[choise_correct]?>" />
      <label for="radio"><?=$q_choise[choise_detail]?></label></td>
  </tr>
<? 
	} //choise
?> 
<? 
} //question
?>
   <tr>
   <input type="hidden" name="question" value="<?=$i?>" />
   <input type="hidden" name="lesson_id" value="<?=$lesson_id?>" />
   <input type="hidden" name="m_id" value="<?=$m_id?>" />
    <td align="center"><input name="btnsubmit" type="submit" id="btnsubmit" value="ส่งคำตอบ" /></td>
  </tr>
</table>
</form>
<?PHP
if(isset($_POST["btnsubmit"])){
	$num = $_POST["question"];
	$lesson_id = $_POST["lesson_id"];
	$m_id = $_POST["m_id"];
	for($i = 0;$i<=$num;$i++){
		$sum += $_POST["radio".$i];
	}
	//echo "lesson_id='$lesson_id'&m_id='$m_id'&ex_score='$sum'";
	echo "กำลังทำการบันทึกคะแนน";
	$url = "http://ielearn.rmutl.ac.th/service.php?method=php_savescore&lesson_id='$lesson_id'&m_id='$m_id'&ex_score='$sum'";
	echo $url;
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=$url\" />";
	//echo "<meta http-equiv='refresh' content='0;URL=' />";
	//format=json&method=s_savescore&lesson_id=2&m_id=3&ex_score=9
	//php_savescore
}
?>
</body>
</html>